<?php
class Sys extends stdClass
{
	static $settings;
	static $dbg;	
	
	/*================================================*/
	public function getSettings()
	{
		return $this->settings;
	}	
	/*================================================*/
	public function getSetting($settName, $def=null)
	{
		if (isset($this->settings[$settName])) return $this->settings[$settName];
		elseif (isset($_SESSION[$settName])) return $_SESSION[$settName];
		else return $def;
	}
	/*================================================*/
	public function setSetting($settName, $value)
	{		
		$_SESSION[$settName] = $value;
		$this->settings[$settName] = $value;
	}
	/*================================================*/
	public function delSetting($settName)
	{		
		unset($_SESSION[$settName]);
		unset($this->settings[$settName]);
	}
	/*================================================*/
	public function restoreSetting($settName)
	{
		$this->setSetting($settName, $this->getSetting($settName));		
	}
	/*================================================*/
	public function clearSettings()
	{		
		foreach ($_SESSION as $key => $value)
		{
			$this->delSetting($key);
		}	
		// System variables	
		$this->setSetting('_absolute_path', $_absolute_path);
		$this->setSetting('_live_site', $_live_site);
		$this->setSetting('_site_name', $_site_name);
		
		// Database variables
		$this->setSetting('dbhost', $_host);
		$this->setSetting('dbusername', $_user);
		$this->setSetting('dbpassword', $_password);
		$this->setSetting('dbname', $_dbname);	
		//date
		//$this->setSetting('ViewDate', date("d.m.Y"));		
	}	
	/*================================================*/
	function Sys()
	{		
		//DB
		global $_host, $_user, $_password, $_dbname;	
		//System
		global $access, $item, $id, $option, $_absolute_path, $_live_site, $_site_name;
		
		//global $User_id, $Filial_id, $Prod_id, $Lang;
		//global $Prod_name, $Filial_name;	
		foreach ($_SESSION as $key => $value)
		{
			$this->restoreSetting($key);			
		}	
		// System variables	
		$this->setSetting('_absolute_path', $_absolute_path);
		$this->setSetting('_live_site', $_live_site);
		$this->setSetting('_site_name', $_site_name);
		
		// Database variables
		$this->setSetting('dbhost', $_host);
		$this->setSetting('dbusername', $_user);
		$this->setSetting('dbpassword', $_password);
		$this->setSetting('dbname', $_dbname);
		
		//Cur Session Var		
		/*
		$this->restoreSetting('access');
		$this->restoreSetting('User_id');
		$this->restoreSetting('Filial_id');
		$this->restoreSetting('Prod_id');
		$this->restoreSetting('Lang');
		$this->restoreSetting('Prod_name');		
		$this->restoreSetting('Filial_name');		
		//Stuff Vars		
		$this->setSetting('item', '');
		$this->setSetting('id', '');
		$this->setSetting('option', '');
		*/
		self::$dbg = false;
		return $this;
	}
	/*================================================*/
	public function Deb_PRNT()
	{		
		
		/*
		__LINE__ The current line number of the file.  
__FILE__ The full path and filename of the file. If used inside an include, the name of the included file is returned.  
__FUNCTION__ The function name. (Added in PHP 4.3.0) As of PHP 5 this constant returns the function name as it was declared (case-sensitive). In PHP 4 its value is always lowercased.  
__CLASS__ The class name. (Added in PHP 4.3.0) As of PHP 5 this constant returns the class name as it was declared (case-sensitive). In PHP 4 its value is always lowercased.  
__METHOD__ The class method name. (Added in PHP 5.0.0) The method name is returned as it was declared (case-sensitive).  

		
		*/
		
		
		
		
		
		
		
		
		
		if (!self::$dbg) return;
		foreach ($this->settings as $key => $value)
		{
			echo "<BR>";			
			//echo $key." - ";
			print_r($key);
			echo " - ";			
			//echo "<B>".$value;
			echo "<B>";
			print_r($value);			
			echo "</B>";			
		}	
		echo "<BR>";	
		print_r(get_defined_constants(true));		
		//print_r(get_defined_constants(true));		
	}		
}
?>